package com.zhongkun.datahome.web.controller.common;

import com.zhongkun.datahome.common.core.domain.R;
import com.zhongkun.datahome.service.service.IFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 文件上传 同步oss db双写 目前仅实现了阿里云,七牛云
 */
@RestController
@Api(value = "文件", tags = "文件")
@RequestMapping("/file")
public class FileController {

    @Autowired
    private IFileService fileService;

    /**
     * 文件上传
     * 根据fileType选择上传方式
     *
     * @param file
     * @return
     * @throws Exception
     */
    @ApiOperation("上传文件")
    @PostMapping("/upload")
    public R<String> upload(@RequestParam("file") MultipartFile file) throws Exception {
        return R.ok(fileService.upload(file));
    }
}
